package com.CityHunter.Request;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;

import android.util.Log;

import com.CityHunter.Common.Http;


public class InviteGroupRequest {

	private String inviteGroupPage;

	public InviteGroupRequest(String inviteGroupPage) {
		this.inviteGroupPage = inviteGroupPage;
	}

	public int inviteGroup(int buddyid, int groupid) {
		
		int result = 0;
		
		// Declare NameValuePair to store the data
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("buddyid", Integer.toString(buddyid)));
		params.add(new BasicNameValuePair("groupid", Integer.toString(groupid)));

		// Send Invite Group Request
		Http http = new Http();
		Log.d("Debug", "Sending Request : " + inviteGroupPage);
		JSONArray jsonResponse = http.sendRequest(inviteGroupPage, params);
		try {
			for (int i = 0; i < jsonResponse.length(); i++) {

				result = Integer.parseInt(jsonResponse.getJSONObject(i)
						.getString("result"));
			}
			Log.d("bdyp_Debug", "Response : Invite Group Result = " + result);
		} catch (Exception e) {
			Log.e("bdyp_Error", e.getMessage().toString());
		}
		
		return result;

	}

}
